
package com.tmall.testgen.client.genfile.genxml;

import java.io.File;
import java.util.List;
import java.util.Map;

import com.thoughtworks.xstream.XStream;
import com.tmall.testgen.client.genfile.genjava.bo.MethodSnap;
import com.tmall.testgen.common.bo.interact.back.DBInfo;
import com.tmall.testgen.common.util.FileUtil;

public class ClassInfoForXML {
	
	private static final String  SUFFIX="_snap_data.xml";
	private static final String SRC="/src/";
	

	private String sql;
	
	private DBInfo dbInfo;
	
	
	private List<String> refProjectClassPathes;
	
	private String targetConfigPath;
	
	private Map<String ,MethodSnap> snaps;
	private Map<String ,MethodSnap> mockSnaps;
	
	private static  ClassInfoForXML instanceCache;
	
	private String mockDes;
	
	public static ClassInfoForXML getInstance(){
		return instanceCache;
	}
	public  static  ClassInfoForXML getInstance(Class testClass) throws Exception{
		if(instanceCache!=null)
			return instanceCache;
		
		String content=readFile(testClass);
		XStream xstream = new XStream(); 
		instanceCache=(ClassInfoForXML) xstream.fromXML(content);
		 return    instanceCache;
			
	}
	
	private static String getFilePath(Class testClass){
		return System.getProperty("user.dir")+SRC+(testClass.getName().replaceAll("\\.", "/"))+SUFFIX;
	}
	private static String readFile(Class testClass) throws Exception{
		String filePath=getFilePath(testClass);
		
		File file=new File(filePath);
        if(!file.exists()){
        	throw new Exception("file is not exist!"); 
        }
        return FileUtil.readFile(filePath);
         
         
	}
	
	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public DBInfo getDbInfo() {
		return dbInfo;
	}

	public void setDbInfo(DBInfo dbInfo) {
		this.dbInfo = dbInfo;
	}

	public Map<String, MethodSnap> getSnaps() {
		return snaps;
	}

	public void setSnaps(Map<String, MethodSnap> snaps) {
		this.snaps = snaps;
	}
	public List<String> getRefProjectClassPathes() {
		return refProjectClassPathes;
	}
	public void setRefProjectClassPathes(List<String> refProjectClassPathes) {
		this.refProjectClassPathes = refProjectClassPathes;
	}
	public String getTargetConfigPath() {
		return targetConfigPath;
	}
	public void setTargetConfigPath(String targetConfigPath) {
		this.targetConfigPath = targetConfigPath;
	}
    public Map<String, MethodSnap> getMockSnaps() {
        return mockSnaps;
    }
    public void setMockSnaps(Map<String, MethodSnap> mockSnaps) {
        this.mockSnaps = mockSnaps;
    }
    public String getMockDes() {
        return mockDes;
    }
    public void setMockDes(String mockDes) {
        this.mockDes = mockDes;
    }

	
	
}
